package tani.bnn.com.mbilling.utility;


import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.jdbc.JDBCAppender;


/**
 * @author netesh.thukral
 *
 */
public class LoggerUtility {
	private static  Logger log = null;
	private static FileAppender fileAppender = null;
	private static JDBCAppender jdbcAppender = null;
	private static ConsoleAppender consoleAppender = null;

	/**
	 * 
	 * @param appender
	 * @return
	 */
	public static Logger getPollingLogger(String appender){

		if(log == null){
			log = Logger.getRootLogger();
			String date = DateUtils.now("dd.MM.yy");
			String logDir = Utility.getAppUtility().getProperty("log");
			try{
				if("FileAppender".equals(appender)){
					String logFileName = date+"_poll_log.log";
					fileAppender = new FileAppender(new SimpleLayout(),logDir+logFileName);
					log.addAppender(fileAppender);
					log.setLevel(Level.ALL);
				}
				 if("ConsoleAppender".equals(appender)){
					consoleAppender = new ConsoleAppender();
					log.addAppender(consoleAppender);
					log.setLevel(Level.ALL);
				 }
				 if("JDBCAppender".equals(appender)){
					jdbcAppender = new JDBCAppender();
					log.addAppender(jdbcAppender);
				 }
				 
			}catch(Exception e){}
		}
		return log;
	}
}